package cn.patient.pp.module.patients.controller.admin;

import cn.patient.pp.framework.apilog.core.annotation.ApiAccessLog;
import cn.patient.pp.framework.common.pojo.CommonResult;
import cn.patient.pp.module.patients.controller.admin.vo.*;
import cn.patient.pp.module.patients.service.DataComparisonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.ServerEndpoint;
import java.util.List;

import static cn.patient.pp.framework.apilog.core.enums.OperateTypeEnum.GET;
import static cn.patient.pp.framework.apilog.core.enums.OperateTypeEnum.IMPORT;

@Tag(name = "管理后台 - 数据统计分析 - 数据对比")
@RestController
@RequestMapping("/dataComparison")
@Validated
public class DataComparisonController {

    @Resource
    private DataComparisonService dataComparisonService;

    @PostMapping("/all")
    @Operation(summary = "数据对比")
    @ApiAccessLog(operateType = GET)
    //@PreAuthorize("@ss.hasPermission('dataComparison:all')")
    public CommonResult<List<DataComparisonRespVO>> getDataComparison(@RequestBody DataComparisonReqVO reqVO) {
        List<DataComparisonRespVO> dataComparisonRespVOs = dataComparisonService.getDataComparison(reqVO);
        return CommonResult.success(dataComparisonRespVOs);
    }

    @PostMapping("/typeSummary")
    @ApiAccessLog(operateType = GET)
    @Operation(summary = "患者类型统计")
    public CommonResult<PatientTypeStatsRespVO> getPatientTypeSummary(
            @RequestBody DataComparisonReqVO reqVO) {
        PatientTypeStatsRespVO stats = dataComparisonService.getPatientTypeStatistics(reqVO);
        return CommonResult.success(stats);
    }

    @PostMapping("/ageStats")
    @ApiAccessLog(operateType = GET)
    @Operation(summary = "各年龄患者数量统计")
    public CommonResult<List<AgeCountVO>> getPatientAgeStatistics(
            @RequestBody DataComparisonReqVO reqVO) {
        return CommonResult.success(dataComparisonService.getPatientAgeStatistics(reqVO));
    }

    // in DataComparisonController.java

    @PostMapping("/subDbStatusStats")
    @ApiAccessLog(operateType = GET)
    @Operation(summary = "当前机构拆库状态统计")
    public CommonResult<PatientTypeStatsRespVO> getOrgSubDbStatusStats(
            @RequestBody DataComparisonReqVO reqVO) {
        PatientTypeStatsRespVO stats = dataComparisonService.getOrgSubDbStatusStatistics(reqVO);
        return CommonResult.success(stats);
    }

    @PostMapping("/dangerBehaviorStats")
    @ApiAccessLog(operateType = GET)
    @Operation(summary = "危险行为患者人数统计")
    public CommonResult<DangerBehaviorStatsVO> getDangerBehaviorStats(
            @RequestBody DataComparisonReqVO reqVO) {
        DangerBehaviorStatsVO stats = dataComparisonService.getDangerBehaviorStatistics(reqVO);
        return CommonResult.success(stats);
    }
}
